<%--
  Created by IntelliJ IDEA.
  User: 12700
  Date: 2025/8/30
  Time: 11:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>登录页</title>
    <link rel="stylesheet" href="css/login.css">
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
      $(document).ready(function () {
        $("[value='登录']").click(function () {
          var username=$("#username").val();
          var password=$("#password").val();
          $.get("login/login",{"username":username,"password":password},function (b) {
            JSON.stringify(b);
            if(b){
              alert("登录成功")
              localStorage.setItem('savedUsername', username);
              $.get("login/select",{"username":username},function (role) {
                JSON.stringify(role);
                if(role=="用户"){
                  window.location.href="pages/users/Users.jsp";
                }else if(role=="物流员"){
                  window.location.href="pages/couriers/Couriers.jsp";
                }else if(role=="管理员"){
                  window.location.href="pages/admins/Admins.jsp";
                };
              });
            }else {
              alert("用户名或密码错误!");
              window.location.href="index.jsp";
            };
          });
        });
      });
    </script>
  </head>
  <body>
  <div class="label">
    <div class="box">
      <div class="box-left">
      <div><img src="images/rest.jpeg" alt=""></div>
      </div>
      <div class="box-right">
        <table>
          <tr>
            <h2>登录</h2>
          </tr>
          <tr>
            <p>账户:</p>
            <input type="text" id="username"> <br>
            <p>密码:</p>
            <input type="password" id="password"> <br>
            <br>
            <input type="button" value="登录"><br>
            <div>
              <a href="pages/login/register.jsp">还没有账户？点击此处前往注册</a><br>
              <a href="pages/login/forgetPassword.jsp">忘记密码？</a>
            </div>
          </tr>
        </table>
      </div>
    </div>
  </div>
  </body>
</html>
